﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;
using System.Data;

namespace Our.Umbraco.uDbCompare
{
    public class uDbCompareUI
    {

        public static void SetLinkCell(TableCell cell, string text, string url)
        {
            System.Web.UI.WebControls.HyperLink link = new HyperLink();
            link.Text = text;
            link.NavigateUrl = url;
            link.Target = "_blank";
            cell.Controls.Add(link);
        }

        public static void SetCellColour(TableCell cell, DbCompareMatch match)
        {
            switch (match)
            {
                case DbCompareMatch.Matching:
                    cell.BackColor = System.Drawing.Color.Green;
                    break;
                case DbCompareMatch.Missing:
                    cell.BackColor = System.Drawing.Color.Red;
                    break;
                case DbCompareMatch.NonMatching:
                    cell.BackColor = System.Drawing.Color.Yellow;
                    break;
            }
        }

        public static TableCell GetCellFromColumnName(GridViewRow row, string columnName)
        {
            TableCell cell = null;
            DataRowView drv = row.DataItem as DataRowView;
            for (int i = 0; i < drv.Row.Table.Columns.Count; i++)
            {
                if (drv.Row.Table.Columns[i].ColumnName == columnName)
                    cell = row.Cells[i];
            }
            return cell;
        }
    }
}
